﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Hook.MenuAssets
{
    public class MenuPane
    {
        public List<MenuItem> PaneList;

        public Vector3 Position;

        public MenuPane()
        {
            PaneList = new List<MenuItem>();
        }

        public void AddMenuItem(MenuItem MI)
        {
            MI.Sprite.Position = Position + MI.Position;
            if(MI is ScreenButton)
            {
                ((ScreenButton)MI).TextSprite.Position = Position + MI.Position;
            }
            PaneList.Add(MI);
        }

        /*public MenuItem LeftClickedItem()
        {
            MenuItem ClickedItem = null;
            foreach(MenuItem MI in PaneList)
            {
                if(MouseInBounds(MI) && Mouse.GetState().LeftButton == ButtonState.Pressed)
                {
                    ClickedItem = MI;
                }
            }
            return ClickedItem;
        }

        public MenuItem MouseOverItem()
        {
            MenuItem HoverItem = null;
            foreach(MenuItem MI in PaneList)
            {
                if(MouseInBounds(MI))
                {
                    HoverItem = MI;
                }
            }
            return HoverItem;
        }

        public bool MouseInBounds(MenuItem MI)
        {
            float MouseX = Mouse.GetState().X;
            float MouseY = Mouse.GetState().Y;
            Vector2 Origin = Position + MI.Position;

            if(MouseX > Origin.X - MI.Dimension.X / 2 &&
                MouseX < Origin.X + MI.Dimension.X / 2 &&
                MouseY > Origin.Y - MI.Dimension.Y / 2 &&
                MouseY < Origin.Y + MI.Dimension.Y / 2)
            {
                return true;
            }
            else
            {
                return false;
            }
        }*/

        public void Update(GameTime gt)
        {
            foreach(MenuItem MI in PaneList)
            {
                if(MI is ScreenButton)
                {

                    ((ScreenButton)MI).Update(gt);
                }
                else
                {
                    MI.Update(gt);
                }
            }
        }
        public void Draw(SpriteBatch sb)
        {
            foreach(MenuItem MI in PaneList)
            {
                if(MI is ScreenButton)
                {

                    ((ScreenButton)MI).Draw(sb);
                }
                else
                {
                    MI.Draw(sb);
                }
            }
        }
    }
}
